package com.coscoshipping.rams.demo.controller;


import com.coscoshipping.rams.demo.pojo.dto.dict.AEncryptDTO;
import com.coscoshipping.rams.demo.pojo.vo.AEncryptVO;
import com.coscoshipping.rams.demo.service.IAEncryptService;
import com.coscoshipping.rams.utils.base.Result;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhaoyin.yang
 * @since 2024-07-12
 */
@Slf4j
@Tag(name = "加解密+脱敏测试类")
@Validated
@RestController
@RequestMapping("/aEncrypt")
public class AEncryptController {

    @Autowired
    private IAEncryptService encryptService;


    /**
     * @description 测试查询 普通参数 拦截器对结果对象进行解密
     * @param id
     * @return: com.coscoshipping.rams.demo.entity.AEncrypt
     * @author zhaoyin.yang
     * @date 2024/4/3 16:15
     */
    @ApiOperationSupport(order = 1)
    @Operation(summary = "测试查询")
    @PostMapping("/getAEncryptById")
    public Result<AEncryptVO> getAEncryptById(@RequestParam("id")Integer id){
        return Result.data(encryptService.getAEncryptById(id));
    }


    /**
     * @description 测试插入 传参为对象，拦截器对含有加密注解的对象的属性 进行自动加密
     * @param aEncrypt
     * @return: int
     * @author zhaoyin.yang
     * @date 2024/4/3 16:15
     */
    @ApiOperationSupport(order = 2)
    @Operation(summary = "测试插入")
    @PostMapping("/addAEncrypt")
    public Result addAEncrypt(@RequestBody AEncryptDTO aEncrypt){
        encryptService.addAEncrypt(aEncrypt);
        return Result.success();
    }


    /**
     * @description 测试查询 查询结果为list 需要对list结果里的对象属性进行解密
     * @return: java.util.List<com.coscoshipping.rams.demo.entity.AEncrypt>
     * @author zhaoyin.yang
     * @date 2024/4/3 16:15
     */
    @ApiOperationSupport(order = 3)
    @Operation(summary = "测试查询结果为list")
    @PostMapping("/getAllAEncrypts")
    public Result<List<AEncryptVO>> getAllAEncrypts(){
        System.out.println("---> " + Thread.currentThread());
        return Result.data(encryptService.getAllAEncrypts());
    }


    /**
     * @description 测试查询 普通参数加密
     * @param mobile
     * @return: java.util.List<com.coscoshipping.rams.demo.entity.AEncrypt>
     * @author zhaoyin.yang
     * @date 2024/4/3 16:15
     */
    @ApiOperationSupport(order = 4)
    @Operation(summary = "测试普通参数加密mobile")
    @PostMapping("/getAEncryptByPhone")
    public Result<List<AEncryptVO>> getAEncryptByPhone(@RequestParam("mobile")String mobile){
        return Result.data(encryptService.getAEncryptByPhone(mobile));
    }

}
